package com.sanpu.kxe.business.repay.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.business.trade.bean.SupportBankOutput;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

/**
 * Description：可支持银行
 * Created by 薛勇军 on 2019/4/26.
 */

public class RepaySupportAdapter extends BaseAdapter {

    private Context mContext;

    private List<SupportBankOutput> bankOutputs = new ArrayList<>();

    public RepaySupportAdapter(Context mContext) {
        this.mContext = mContext;
    }

    /**
     * 刷新数据
     */
    public void setNotifyData(List<SupportBankOutput> bankOutputs) {
        this.bankOutputs = bankOutputs;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (bankOutputs == null)
            return 0;
        return bankOutputs.size();
    }

    @Override
    public SupportBankOutput getItem(int position) {
        if (bankOutputs == null)
            return null;
        return bankOutputs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_repay_support, null);
        }
        ImageView bankIv = ButterKnife.findById(convertView, R.id.bankIv);
        TextView bankNameTv = ButterKnife.findById(convertView, R.id.bankNameTv);

        SupportBankOutput bankOutput = getItem(position);
        if (bankOutput != null) {
            JKImageLoader.getInstance().displayImage(mContext,
                    UrlConstants.getBaseUrl() + bankOutput.getLogoPath(), bankIv);
            if (!TextUtils.isEmpty(bankOutput.getBankName())) {
                bankNameTv.setText(bankOutput.getBankName());
            }
        }
        return convertView;
    }
}
